package controller

import (
	"gin/response"
	"gin/service"
	"gin/types"
	"github.com/gin-gonic/gin"
)

type Project struct {
}

// 获取进行中的项目列表请求参数
type GetInProgressProjectListQuery struct {
	TenantId uint64 `json:"tenant_id" binding:"required"`
}

// GetAllSpendReq 获得租户 所有项目花费资源统计
type GetAllSpendReq struct {
	TenantId uint64 `json:"tenant_id" binding:"required"`
}

// 获取进行中的项目列表
func (c *Project) GetInProgressProjectList(ctx *gin.Context) {

	var QueryParam GetInProgressProjectListQuery
	err := ctx.ShouldBindJSON(&QueryParam)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var ProjectService service.Project
	resData, queryErr := ProjectService.GetInProgressProjectList(QueryParam.TenantId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// GetAllSpend 获得租户项目总花费
func (c *Project) GetAllSpend(ctx *gin.Context) {
	var req GetAllSpendReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var ProjectService service.Project
	resData, queryErr := ProjectService.GetAllSpendReq(req.TenantId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProjectListV2 获取项目列表
func (c *Project) ProjectListV2(ctx *gin.Context) {
	var tenantId = service.GetInt64FromContext(ctx, "tenant_id")
	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectListV2(ctx, tenantId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProjectManResourceDistribution 项目人力资源分布情况
func (c *Project) ProjectManResourceDistribution(ctx *gin.Context) {
	var req types.ProjectManResourceDistributionReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectManResourceDistribution(ctx, req.ProjectId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProjectDetail 项目详情
func (c *Project) ProjectDetail(ctx *gin.Context) {
	var req types.ProjectDetailReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectDetail(ctx, req.ProjectId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

func (c *Project) ProjectTaskSubmitCountByDate(ctx *gin.Context) {
	var req types.ProjectTaskSubmitCountByDateReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectTaskSubmitCountByDate(req.ProjectId, req.DateStringStart, req.DateStringEnd)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProjectTaskDoneGroupedCount 项目任务完成数量分组统计
func (c *Project) ProjectTaskDoneGroupedCount(ctx *gin.Context) {
	var req types.ProjectTaskDoneGroupedCountReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectTaskDoneGroupedCount(ctx, req.ProjectId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProjectStepCategoryDoneCount 项目环节产出情况
func (c *Project) ProjectStepCategoryDoneCount(ctx *gin.Context) {
	var req types.ProjectStepCategoryDoneCountReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectStepCategoryDoneCount(req.ProjectId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProjectAssetPreviewCheck 资产巡检
func (c *Project) ProjectAssetPreviewCheck(ctx *gin.Context) {
	var req types.ProjectAssetPreviewCheckReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectAssetPreviewCheck(ctx, req.ProjectId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// ProjectInprogressEpisode 项目进行中剧集
func (c *Project) ProjectInprogressEpisode(ctx *gin.Context) {
	var req types.ProjectInprogressEpisodeReq
	err := ctx.ShouldBindJSON(&req)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	var ProjectService service.Project
	resData, queryErr := ProjectService.ProjectInprogressEpisode(ctx, req.ProjectId)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}
